package org.pay.gate.model;

import org.pay.PayUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class PayGateReqDataModel {


    /**
     * pay
     *      * "BuyerID": "224802381951832089",
     *      * "TxType": "22",
     *      * "BillNumber": "144420221101164528",
     *      * "Amount": 100,
     *      * "LocalDate": "20221101",
     *      * "LocalTime": "164528",
     *      * "Detail": "測試商品 x1,測試商品 x2,測試商品 x3"
     */

    /**
     * refund
     * {
     *      *  "TxType": "23",
     *      *  "OrderNumber": "600000031667292367",
     *      *  "BillNumber": "144420221101164528",
     *      *  "LocalDate": "20221101",
     *      *  "LocalTime": "164605"
     *      *  }
     */

    /**
     * check
     * {
     * * "TxType": "24",
     * * "BillNumber": "144420221101164528"
     * * }
     */
    //pay 22
    String TxType;
    //BuyerID string 掃描的支付條碼
    String BuyerID;

    //BillNumber 交易編號 格式：shopID+YYYYMMDDHHmmss
    //BillNumber 例如店家編號為 1444 時 交易編號 144420221101164528
    String BillNumber;
    int Amount;
    //string Y 8交易日期 (YYYYMMDD)Ex: 20211231
    //。
    private String LocalDate;

    //LocalTime string Y 6 交易時間 (hhmmss)Ex: 235959
    private String LocalTime;

    //Detail string N 999 交易品項。填入規格[“商品”]+[“小寫 x”]+[“數字”] ex：刷卡機 x1,紙捲 x20,連接線 x1
    private String Detail;

    String OrderNumber;

    public static PayGateReqDataModel buildPayDataModel(String shopID, String buyerId, double amount, String detail) {
        String billNumber = PayUtils.buildBillNumber(shopID);
        int length=billNumber.length();
        String localTime= billNumber.substring(length-6,length);
        String localDate= billNumber.substring(length-14,length-6);
   /*     SimpleDateFormat dmDate = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String dateran = dmDate.format(date);
        String localDate = dateran.substring(0, 8);
        String localTime = dateran.substring(8, 14);*/
        return new PayGateReqDataModel("22", buyerId, billNumber, (int) Math.floor(amount * 100), localDate, localTime, detail);
    }

    public static PayGateReqDataModel buildCheckDataModel(String billNumber) {
        return new PayGateReqDataModel("24", billNumber);
    }


    public static PayGateReqDataModel buildRefundDataModel(String orderNumber, String billNumber, String localDate, String localTime) {
        return new PayGateReqDataModel("23", orderNumber, billNumber, localDate, localTime);
    }


    public PayGateReqDataModel(String txType, String orderNumber, String billNumber, String localDate, String localTime) {
        this.TxType = txType;
        this.OrderNumber = orderNumber;
        this.BillNumber = billNumber;
        this.LocalDate = localDate;
        this.LocalTime = localTime;
    }

    public PayGateReqDataModel(String txType, String billNumber) {
        this.TxType = txType;
        this.BillNumber = billNumber;
    }

    public PayGateReqDataModel(String txType, String buyerID, String billNumber, int amount, String localDate, String localTime, String detail) {
        this.TxType = txType;
        this.BuyerID = buyerID;
        this.BillNumber = billNumber;
        this.Amount = amount;
        this.LocalDate = localDate;
        this.LocalTime = localTime;
        this.Detail = detail;
    }

    public PayGateReqDataModel(String txType, String billNumber, int amount, String localDate, String localTime, String detail, String orderNumber) {
        TxType = txType;
        BillNumber = billNumber;
        Amount = amount;
        LocalDate = localDate;
        LocalTime = localTime;
        Detail = detail;
        OrderNumber = orderNumber;
    }

    public String getTxType() {
        return TxType;
    }

    public void setTxType(String txType) {
        TxType = txType;
    }

    public String getBillNumber() {
        return BillNumber;
    }

    public void setBillNumber(String billNumber) {
        BillNumber = billNumber;
    }

    public int getAmount() {
        return Amount;
    }

    public void setAmount(int amount) {
        Amount = amount;
    }

    public String getLocalDate() {
        return LocalDate;
    }

    public void setLocalDate(String localDate) {
        LocalDate = localDate;
    }

    public String getLocalTime() {
        return LocalTime;
    }

    public void setLocalTime(String localTime) {
        LocalTime = localTime;
    }

    public String getDetail() {
        return Detail;
    }

    public void setDetail(String detail) {
        Detail = detail;
    }

    @Override
    public String toString() {
        return "PayGateReqDataModel{" +
                "TxType='" + TxType + '\'' +
                ", BillNumber='" + BillNumber + '\'' +
                ", Amount=" + Amount +
                ", LocalDate='" + LocalDate + '\'' +
                ", LocalTime='" + LocalTime + '\'' +
                ", Detail='" + Detail + '\'' +
                ", OrderNumber='" + OrderNumber + '\'' +
                '}';
    }
}
